//table头信息 不变
var tp_columnData = [
    {"Width": "14%", "ColumnName": "客户Id"},
    {"Width": "14%", "ColumnName": "跟进客户"},
    {"Width": "16%", "ColumnName": "计划跟进时间"},
    {"Width": "14%", "ColumnName": "跟进类型"},
    {"Width": "14%", "ColumnName": "联系人"},
    {"Width": "14%", "ColumnName": "手机号"},
    {"Width": "14%", "ColumnName": "操作"}
];

//操作按钮 不变
var tp_operateHtml = "<div class='form-inline'>" +
    " <button type='button' class='btn btn-primary innerButtons'  value='view'>查看</button>" +
    "</div>";


//用户管理分页函数
var gotoPage = function (index) {
    var url = webPath + "/crm/1";
    var trackTime = $("#trackTime").val();
    var trackType = $("#trackTime").val();
    var trackCustomer = $("#trackTime").val();
    var postData = {
        "pageSize": pageSize, "pageNumber": index,
        "trackTime": trackTime, "trackType": trackType, "trackCustomer": trackCustomer
    };
    var options = {"passArguments": index}
    postAjax(url, postData, gotoPageSuccess, options);
};

var gotoPageSuccess = function (result, passArguments) {
    //TODO remove
    var result = '{"totalNumber":3,"list":[{"customerId":"22","customerName":"lisi","recordTime":"20160203",' +
        '"nextCallTime":"20150505","contectMan":"Ak","phoneNumber":"12345678911"}]}';
    var columnList = ["customerId", "customerName", "recordTime", "nextCallTime", "contectMan", "phoneNumber"];
    //$.post(url, postData, function (result) {
    cleanTableAndPage("trackPlanTable");
    var jsonData = $.parseJSON(result);
    //画table
    $("#trackPlanTable").MakeTable(false, tp_columnData, jsonData.list, tableClass, columnList, tp_operateHtml);
    //画分页
    $("#trackPlanTable").after(comPagination(passArguments, pageSize, jsonData.totalNumber, "gotoPage", "trackPlanP"));

    //Table中操作栏 修改 解锁 查看
    $("#trackPlanTable button").click(function () {
        var that = $(this);
        var customerId = getTrackPlanId(that);
        var buttonType = that.val();
        that.val() === "view" ?
            getPage(webPath + "/crm/getViewRecords/" + customerId + "/0.do") :
            alert("something wrong");
    });
}

//查询按钮行为
$('#searchTrackBtn').click(function () {
    gotoPage(1);
});

//获取id 方便提交 TODO Change
var getTrackPlanId = function (that) {
    return that.closest("tr").find("td div")[1].innerHTML;
}

